package com.woniuxy02;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-11-05 14:12
 */
public class Test01 {
    public static void main(String[] args) throws ParseException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入日期");
        String str = scanner.nextLine();
        DateFormat df =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        //字符串转日期
        Date date = df.parse(str);
        System.out.println(date);

    }

    private static void test07() {
        Scanner scanner = new Scanner(System.in);

        System.out.println("整数");
        int num = scanner.nextInt();
        System.out.println(num);

        //nextLine()接受的问题，前面有输入，必须先调用一次，再让用户输入
        scanner.nextLine();

        System.out.println("字符串");
        String str = scanner.nextLine();
        System.out.println(str);
    }

    private static void test06() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入字符串");
        //接收到回车或者空格，表示输入结束
//        String next = scanner.next();
        //接收到回车，表示输入结束
        String next = scanner.nextLine();
        System.out.println(next);
    }

    private static void test05() throws ParseException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入日期");
        String str = scanner.next();
        DateFormat df =new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        //字符串转日期
        Date date = df.parse(str);
        System.out.println(date);
    }

    private static void test04() {
        Date date = new Date();
        //DateFormat对象就是来表示日期格式
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String str = df.format(date);
        System.out.println(date);
        System.out.println(str);
    }

    private static void test03() {
        //日期转字符串
        Date date = new Date();
        System.out.println(date);
        //自己拼接，不方便
        System.out.println(date.getYear() + 1900 + "-" + (date.getMonth() + 1) + "-" + date.getDate());
    }

    private static void test02() {
        Date date = new Date();
        System.out.println(date.getYear() + 1900);
        System.out.println(date.getMonth() + 1);
        System.out.println(date.getDate());
    }

    private static void test01() {
        //无参构造，就是当前时间的一个日期对象
        Date date = new Date();
        System.out.println(date);

        //        System.out.println(System.currentTimeMillis());
        //        System.out.println(System.currentTimeMillis());
        long currentTimeMillis = System.currentTimeMillis();
        Date date1 = new Date(currentTimeMillis);
        System.out.println(date1);

        Date date2 = new Date(1000);
        System.out.println(date2);
    }
}
